package ${allPackage}${servicePackage}.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${allPackage}${daoPackage}.${domainUpper}Dao;
import ${allPackage}${servicePackage}.${domainUpper}Service;
import ${allPackage}${domainPackage}.${domainUpper};
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * ${domainDesc}Service实现类
 * @author 自动生成
 * @description 自动生成
 * @create ${createTime}
 */
@Service("${domain}Service")
@Transactional(rollbackFor = Throwable.class)
public class ${domainUpper}ServiceImpl extends ServiceImpl<${domainUpper}Dao, ${domainUpper}> implements ${domainUpper}Service {

    private final ${domainUpper}Dao ${domain}Dao;

    public ${domainUpper}ServiceImpl(${domainUpper}Dao ${domain}Dao) {
        this.${domain}Dao = ${domain}Dao;
    }

    /**
     * 分页查询列表
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageInfo<${domainUpper}> getList(int page, int limit) {
        QueryWrapper<${domainUpper}> wrapper = new QueryWrapper<>();
        PageHelper.startPage(page, limit);
        List<${domainUpper}> list = ${domain}Dao.selectList(wrapper);
        return new PageInfo<${domainUpper}>(list);
    }

    /**
     * 新增信息
     * @param ${domain}
     */
    @Override
    @SneakyThrows
    public void saveOne(${domainUpper} ${domain}) {
        int count = ${domain}Dao.insert(${domain});
        if (count!=1){
            throw new Exception("保存失败");
        }
    }

    /**
     * 更新信息
     * @param ${domain}
     */
    @Override
    @SneakyThrows
    public void update(${domainUpper} ${domain}) {
        int count = ${domain}Dao.updateById(${domain});
        if (count!=1){
            throw new Exception("更新失败");
        }
    }

    /**
     * 删除信息
     * @param primaryKey
     */
    @Override
    @SneakyThrows
    public void delete(String primaryKey) {
        int count = ${domain}Dao.deleteById(primaryKey);
        if (count!=1){
            throw new Exception("删除失败");
        }
    }
}
